<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录界面</title>
    <!-- 引入 Google Fonts 字体 -->
    <link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@400;600&display=swap" rel="stylesheet">
    <!-- 引入 jquery CDN -->
    <script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
    <style>
        body {
            font-family: 'Montserrat', sans-serif;
            background-image: url('../pictures/bk_image2.jpg');
            background-size: cover;
            background-position: center;
            background-repeat: no-repeat;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            backdrop-filter: blur(5px);
            /* 背景模糊效果 */
        }

        .login-container {
            background-color: rgba(255, 255, 255, 0.9);
            padding: 40px;
            border-radius: 15px;
            box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
            width: 350px;
            animation: fadeIn 0.5s ease-out;
            /* 淡入动画 */
        }

        @keyframes fadeIn {
            from {
                opacity: 0;
                transform: translateY(-20px);
            }

            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        .login-container h2 {
            text-align: center;
            margin-bottom: 30px;
            color: #333;
            font-size: 28px;
        }

        .form-group {
            margin-bottom: 20px;
        }

        .form-group label {
            display: block;
            margin-bottom: 8px;
            color: #666;
            font-size: 14px;
            font-weight: 600;
        }

        .form-group input {
            width: 100%;
            padding: 12px;
            box-sizing: border-box;
            border: 1px solid #ccc;
            border-radius: 8px;
            font-size: 16px;
            transition: border-color 0.3s ease;
        }

        .form-group input:focus {
            outline: none;
            border-color: #007BFF;
            box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.2);
        }

        .form-group button {
            width: 100%;
            padding: 14px;
            background-color: #007BFF;
            color: #fff;
            border: none;
            border-radius: 8px;
            cursor: pointer;
            font-size: 16px;
            font-weight: 600;
            transition: background-color 0.3s ease;
        }

        .form-group button:hover {
            background-color: #0056b3;
            transform: scale(1.02);
            /* 悬停时放大效果 */
        }
    </style>
</head>

<body>
    <div class="login-container">
        <h2>用户登录</h2>
        <form id="loginForm">
            <div class="form-group">
                <label for="username">用户名</label>
                <input type="text" id="username" name="username" required>
            </div>
            <div class="form-group">
                <label for="password">密码</label>
                <input type="password" id="password" name="password" required>
            </div>
            <div class="form-group">
                <button type="button" onclick="login()">登录</button>
            </div>
        </form>
    </div>

    <script>
        var usernameInput = document.getElementById("username");
        var passwordInput = document.getElementById("password");

        function login() {
            var username = usernameInput.value;
            var password = passwordInput.value;

            var usernamePrefix = username.slice(0, 4);

            // 取消注释以使用 AJAX 请求
            $.ajax({
                method: 'Post', // 向后端发起请求的方式
                url: '/search', // 向后端指定的url发起请求
                dataType: 'json', // 告知server，我需要什么格式
                contentType: 'application/json;charset=utf-8', // 告知server，我给你的是什么格式
                data: JSON.stringify({
                    'username': username,
                    'password': password
                }),
                success: function (data) {
                    // 成功得到结果
                    var result = data.status;
                    if(usernamePrefix==='root'&&result==='success'){
                        window.location.href = './MainPagehtml/UserCreate.html';
                    }else if(result==='success'){
                        window.location.href = './MainPagehtml/MainPage.html';
                    }else{
                        alert("用户名或密码错误，登录失败！");    
                    }
                }
            });
        }
    </script>
</body>

</html>
